package tower.ai.base.chat.config;

import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.qdrant.QdrantVectorStore;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@AutoConfigureAfter(OllamaConfig.class)
@ConditionalOnProperty(prefix = "spring.qdrant", name = "enabled", havingValue = "true", matchIfMissing = false)
public class QdrantConfig {

    @Bean
    public QdrantClient qdrantClient() {

        QdrantGrpcClient.Builder grpcClientBuilder =
                QdrantGrpcClient.newBuilder(
                        "localhost",
                        6333,
            false);
        grpcClientBuilder.withApiKey("greenckw5");
        return new QdrantClient(grpcClientBuilder.build());
    }

    @Bean(name="qdrantVectorStore")
    public QdrantVectorStore qdrantVectorStore(EmbeddingModel embeddingModel, QdrantClient qdrantClient) {
        return new QdrantVectorStore(qdrantClient, "chenkw-ollama-embedding", embeddingModel, true);
    }
}
